package com.cloud.service;

import com.cloud.dao.OrderDao;
import com.cloud.entity.Order;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * @BelongsProject: my
 * @BelongsPackage: com.cloud.service
 * @Author: ji ge
 * @CreateTime: 2024-02-04  14:43
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
public class OrderServiceImpl implements OrderService{
    @Resource
    private OrderDao orderDao;
    @Resource
    private StorageService storageService;
    @Resource
    private AccountService accountService;
    @Override
    public void create(Order order) {
        log.info("新建订单");
        orderDao.create(order);
        log.info("库存扣减");
        storageService.decrease(order.getProductId(),order.getCount());
        log.info("扣钱");
        accountService.decrease(order.getUserId(),order.getMoney());
        log.info("订单改状态");
        orderDao.update(order.getUserId(),0);
    }
}
